/**
 * This class will implement the report controller to our system. 
 * @author Gil Levinson
 * @author Boris Fradlis
 * @author Yogev Levi
 * @author Hila Porat
 */
package control;

// Imports ********************************************

import java.io.Serializable;
import system.SystemMode;
import system.SystemTypes;
import system.VCP;
import system.VcpClient;
import vcpClasses.ParkingLot;
import vcpClasses.User;

// Start of SetRatesController ***************************

public class ReportsController extends AbstractController {

	//Class variables ************************************
	
	private SystemTypes sysType;
	private boolean returned = false;
	
	/**
	 * Unimplemented constructor
	 */
	
	public ReportsController(){};
	
	// controller methods *****************************************
	
	/**
	 * this method will generate new reports
	 * @param sysType - the report to issue
	 * @return the proer result
	 */
	
	public SystemTypes GenerateReport(SystemTypes sysType)
	{
		returned = false;
		sysType.setSysMode(SystemMode.NEW_REPORT);
		boolean flag = SendToServer(sysType);
		while(!returned){}
		if (!flag)
		{
			switch (this.sysType.getSysMode())
			{
				case SYS_ERR:
				{
					this.sysType.setObj("Client - Server Connection Failed!");
					break;
				}
				case DB_CON_ERR:
				{
					this.sysType.setObj("DB connection Failed!");
					break;
				}
				
			default:
				this.sysType.setObj("Unknown failure in process!");
				break;
			}
		}
		return this.sysType;
	}
	
	
	@Override
	public boolean SendToServer(Serializable obj) {
		VCP.client.send(obj);
		sysType = (SystemTypes) VCP.client.getResult();
		if (sysType.getSysMode() != SystemMode.OK)
		{
			returned = true;
			return false;
		}
		returned = true;
		return true;
	}
	
		
	// Getters and Setters ***************************************************

		/**
		 * @return the sysType
		 */
		public SystemTypes getSysType() {
			return sysType;
		}

		/**
		 * @param sysType the sysType to set
		 */
		public void setSysType(SystemTypes sysType) {
			this.sysType = sysType;
		}

		/**
		 * @return the returned
		 */
		public boolean isReturned() {
			return returned;
		}

		/**
		 * @param returned the returned to set
		 */
		public void setReturned(boolean returned) {
			this.returned = returned;
		}
	

}
